package hdgeom.primitives;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

import processing.core.PVector;

public class ArrayFace extends AbstractFace{
	public PVector[] vertices=new PVector[0];
	public int id;

	public ArrayFace() {
	}

	public ArrayFace(PVector v1, PVector v2, PVector v3) {
		vertices = new PVector[]{v1,v2,v3};
	}

	public ArrayFace(PVector v1, PVector v2, PVector v3, PVector v4) {
		vertices = new PVector[]{v1,v2,v3,v4};
	}

	public int size() {
		return vertices.length;
	}

	public PVector get(int i) {
		return vertices[i];
	}

	public PVector set(int i, PVector v) {
		 vertices[i]=v;
		 return v;
	}

	public void turn() {
		for(int i = 0; i < vertices.length; i++)  
        {  
            PVector temp = vertices[i];  
            vertices[i] = vertices[vertices.length - i - 1];  
            vertices[vertices.length - 1] = temp;  
        }  
	}

	public PVector normal() {
		PVector v = PVector.sub(get(1), get(0));
		PVector u = PVector.sub(get(2), get(0));
		PVector normal = new PVector();
		PVector.cross(v, u, normal);
		normal.normalize();
		return normal;
	}

	public void addNode(PVector n) {
		vertices=Arrays.copyOf(vertices, vertices.length+1);
		vertices[vertices.length-1]=n;
		// TODO Auto-generated method stub

	}

	public PVector getNode(int j) {
		// TODO Auto-generated method stub
		return vertices[j];
	}
	

	public int getNNodes() {
		// TODO Auto-generated method stub
		return vertices.length;
	}

	@Override
	public int getNumVertices() {
		// TODO Auto-generated method stub
		return vertices.length;
	}

	@Override
	public void getPosition(int i, float[] coords) {
		// TODO Auto-generated method stub
		PVector v = get(i);
		coords[0] = v.x;
		coords[1] = v.y;
		coords[2] = v.z;
	}

	@Override
	public void setPosition(int i, float x, float y, float z) {
		// TODO Auto-generated method stub
		PVector v = get(i);
		v.set(x, y, z);

	}

}
